package stringdemo;

import java.util.Scanner;

public class StringDemo2UserRegister {
    public static void main(String[] args) {
        //1.定义两个变量来记录正确的用户名和密码
        String rightUserName = "Yusc";
        String rightUserWord = "123456";

        Scanner sc = new Scanner(System.in);
        //有三次输入机会
        for (int i = 0; i < 3; i++) {
            //2.键盘录入用户名和密码
            System.out.println("请输入用户名:");
            String userName = sc.next();
            System.out.println("请输入密码:");
            String userWord = sc.next();
            //3.比较
            if(userWord.equals(rightUserWord) && userName.equals(rightUserName)){
                System.out.println("登录成功!");
                break;
            }else {
                if (i == 2){
                    System.out.println("账号"+userName+"已被锁定!");
                }else {
                    System.out.println("登录失败,账号或密码有误!你还有"+(2-i)+"次机会");
                }

            }
        }

    }
}
